package com.renjie.homework;

public class Programmer {
    private String name;
    private int age;
    private int skill;
    private int year;
    private String level;
    private String company;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        if (age < 18) {
            System.out.println("年龄低于18");
        } else {
            this.age = age;
        }
    }

    public int getSkill() {
        if (skill == 1 || skill == 2 || skill == 3) {
            return skill;
        } else {
            return 0;
        }
    }

    public void setSkill(int skill) {
        this.skill = skill;
    }

    public void setYear(int year) {
        this.year = year;
        if (this.year < 1) {
            this.level = "初级";
        } else if (year < 3) {
            this.level = "中级";
        } else {
            this.level = "高级";
        }
    }

    //只读字段
    public String getLevel() {
        return level;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public Programmer(String name, int skill, int year, String company) {
        this.setName(name);
        this.setYear(year);
        this.setSkill(skill);
        this.setCompany(company);
        this.age = 18;
    }

    public void work() {
        System.out.println("程序员：" + getName() + "年龄为：" + getAge() + "职务为：" + getTitle() + "公司为：" + getCompany());
    }

    private String getTitle() {
        String skillName = "";
        switch (this.skill) {
            case 1:
                skillName = "前端";
                break;
            case 2:
                skillName = "后端";
                break;
            case 3:
                skillName = "全栈";
                break;
        }
        return this.level + skillName;
    }
}
